libsoc_adapter_dep = dependency('libsoc_adapter', method : 'pkg-config', required : false)

hisport_sources = [
  'hisport.cpp',
  'hisport_abi.cpp',
  'interface/i_hisport.cpp',
]

# 在 meson 构建时使用打桩文件，非 meson 构建时使用实际实现
if meson_build
  hisport_sources += '../../../tests/drivers/bus/hisport/drivers/hisport.cpp'
endif

hisport_headers = [
  'hisport.h',
  'interface/i_hisport.h',
]

install_headers(hisport_headers, install_dir: install_inc_dir / 'bus/hisport')

# 根据构建类型设置include路径
hisport_include_dirs = [include_dirs, '..', '../..']

# 如果是meson构建（包括compile和test），添加测试打桩文件的include路径
if meson_build
  hisport_include_dirs += include_directories('../../../tests/drivers/bus/hisport')
endif

# 如果是非meson构建且有libsoc_adapter依赖，添加其include路径
if not meson_build and libsoc_adapter_dep.found()
  hisport_include_dirs += libsoc_adapter_dep.get_variable('includedir', default_value: '')
endif

hisport_lib = shared_library(
    'Hisport',
    hisport_sources,
    include_directories: hisport_include_dirs,
    dependencies: [libsoc_adapter_dep, libmcpp_deps, internal_dep],
    link_args: [],
    name_prefix: 'lib',
    name_suffix: 'so',
    install: true,
    install_dir: drivers_install_dir,
)

hisport_dep = declare_dependency(
    link_with: hisport_lib,
    dependencies: [libsoc_adapter_dep, libmcpp_deps, internal_dep],
)

if build_tests
  custom_target(
    'copy_libHisport',
    output: 'copy_libHisport',
    command: ['cp', hisport_lib.full_path(), drivers_install_dir],
    depends: hisport_lib,
    build_by_default: true,
  )
endif 
